#!/bin/bash			
# ./jmeter_batch.sh run 1000 192.168.0.172 31281

htmls_path=./result # web报告文件目录
scripts_path=./scripts # 脚本目录
logs_path=./jtl # 压测结果目录

theard=$2 # 线程数
am=$3
ip=$4 # ip
port=$5 # port
pr=$6 # ramp-up
ln=$7 # loop-num
backup_path=./backup/

export JVM_ARGS="-Xms8g -Xmx8g"

if [[ $1 = run ]]; then
    mkdir $htmls_path
    mkdir $logs_path
    # 遍历脚本
    for script_path in $(find $scripts_path/* -name "*.jmx"); do
        script_name=${script_path##*/}_${theard}_$pr
	echo $pr
	echo $script_name
        # 生成结果文件
        jmeter -n -t $script_path -JTheard=$theard  -JLN=$ln -JA=$am -JDomain=$ip -JPort=$port -l $logs_path/$script_name.jtl
        # 生产web报告
        jmeter -g $logs_path/$script_name.jtl -o $htmls_path/$script_name
    done
elif
    [[ $1 = clean ]]
then
    find $htmls_path/* | grep -v "index.html" | xargs rm -rf
    rm -rf $logs_path
fi
